home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / gnustuff / tos / smallt~1 / smallt~1.zoo / mstmain.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-05-26  |  20.1 KB  |  782 lines

  1. /***********************************************************************
  2.  *
  3.  *    Main Module
  4.  *
  5.  ***********************************************************************/
  6.  
  7. /***********************************************************************
  8.  *
  9.  * Copyright (C) 1988, 1989, 1990 Free Software Foundation, Inc.
  10.  * Written by Steve Byrne.
  11.  *
  12.  * This file is part of GNU Smalltalk.
  13.  *
  14.  * GNU Smalltalk is free software; you can redistribute it and/or modify it
  15.  * under the terms of the GNU General Public License as published by the Free
  16.  * Software Foundation; either version 1, or (at your option) any later 
  17.  * version.
  18.  * 
  19.  * GNU Smalltalk is distributed in the hope that it will be useful, but WITHOUT
  20.  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
  21.  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
  22.  * more details.
  23.  * 
  24.  * You should have received a copy of the GNU General Public License along with
  25.  * GNU Smalltalk; see the file COPYING.  If not, write to the Free Software
  26.  * Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  
  27.  *
  28.  ***********************************************************************/
  29.  
  30.  
  31. /*
  32.  *    Change Log
  33.  * ============================================================================
  34.  * Author      Date       Change 
  35.  * sbyrne    22 May 90      Improved on Doug's mapping with macro to improve
  36.  *              readability.
  37.  *
  38.  * sbyrne    22 May 90      Short name stuff added, thanks to Doug McCallum.
  39.  *
  40.  * sbyrne    25 Mar 90      ProcessorScheduler is too long of a name for the
  41.  *              Atari; there are uniqueness problems.  Shortened to
  42.  *              ProcScheduler.   Also, fixed quietExecution; wasn't
  43.  *              set when reading from the terminal; should have been
  44.  *              set to false (since the loading of the quiet things
  45.  *              is over).
  46.  *
  47.  * sbyrne    15 Oct 89      Added support for creating an "installed" version of
  48.  *              Smalltalk.  There is now an include file that the
  49.  *              installer can customize for his site that provides
  50.  *              default locations to be checked for the kernel .st
  51.  *              files and the binary image file, but these can be
  52.  *              overidden in two ways: a) by a file of the same
  53.  *              name in the user's current directory, or b)
  54.  *              environment variables SMALLTALK_KERNEL and
  55.  *              SMALLTALK_IMAGE.
  56.  *
  57.  * sbyrne     4 Jul 89      Added support for user init files (in ~/.stinit),
  58.  *              which are invoked on every startup.  Also, added
  59.  *              support for initBlocks, which are blocks that are
  60.  *              stored in the system and invoked on each startup
  61.  *              (these could be used, for example, as an interim
  62.  *              measure for declaring C callouts until the callout
  63.  *              descriptor is converted to a Smalltalk object).
  64.  *
  65.  * sbyrne    10 Mar 89      Added support for automatically loading image file if
  66.  *              it's newer than and of the system source files.
  67.  *
  68.  * sbyrne    27 Dec 88      Created.
  69.  *
  70.  */
  71.  
  72.  
  73. #include "mst.h"
  74. #include "mst.tab.h"
  75. #include "mstinterp.h"
  76. #include "mstcomp.h"
  77. #include "mstsave.h"
  78. #include "mstsym.h"        /* for symbol table profiling */
  79. #include "mstoop.h"        /* indirectly defines oopAt for sym tab prof */
  80. #include "mstpaths.h"
  81. #include "mstmain.h"
  82. #include <stdio.h>
  83. #include <sys/types.h>
  84. #include <sys/stat.h>
  85. #include <sys/file.h>
  86. #if defined(USG)
  87. #include <unistd.h>
  88. #endif
  89.  
  90. #ifndef MAXPATHLEN
  91. #define MAXPATHLEN        1024 /* max length of a file and path */
  92. #endif
  93.  
  94. #ifdef SHORTNAMES
  95. #define MAP_FILE(long, short)    short
  96. #else
  97. #define MAP_FILE(long, short)    long
  98. #endif
  99.  
  100.  
  101. #ifndef atarist
  102. #define INIT_FILE_NAME        ".stinit"
  103. #else
  104. #define INIT_FILE_NAME        "stinit"
  105. #endif
  106.  
  107.  
  108. extern int        yydebug, lexDebug, numFreeOOPs;
  109. extern YYSTYPE        yylval;
  110. extern char        *getenv();
  111.  
  112. #ifdef symbol_table_profiling
  113. extern int        adds, reused, reprobes, hitsOn[];
  114. #endif /* symbol_table_profiling */
  115.  
  116. /* When true, this flag suppresses the printing of execution-related
  117.  * messages, such as the number of byte codes executed by the
  118.  * last expression, etc.
  119.  */
  120. Boolean            quietExecution;
  121.  
  122. char            *kernelFileDefaultPath, *imageFileDefaultPath;
  123.  
  124. static Boolean         processFile(), okToLoadBinary();
  125. static void        loadStandardFiles(), loadUserInitFile(), initPaths(),
  126.             findKernelFile(), parseArgs();
  127. static unsigned long    getFileModifyTime();
  128.  
  129.  
  130. /* Set by cmd line flag.  If true, Smalltalk is more verbose about what it's
  131.  * doing.
  132.  */
  133. static Boolean        verbose = false;
  134.  
  135. /* If true, even both kernel and user method definitions are shown as
  136.  * they are compiled.
  137.  */
  138. static Boolean        traceKernelDeclarations;
  139.  
  140. /* If true, execution tracing is performed when loading kernel method
  141.  * definitions
  142.  */
  143. static Boolean        traceKernelExecution;
  144.  
  145. /* If true, skip date checking of kernel files vs. binary image; pretend
  146.  * that binary image does not exist
  147.  */
  148. static Boolean        ignoreImage;
  149.  
  150.  
  151. /* If non-nil, this is the name of the binary image to load, and overrides
  152.  * the checking of the dates of the kernel source files against the image
  153.  * file date.
  154.  */
  155. static char        *binaryImageName = nil;
  156.  
  157.  
  158. /* Set by command line flag.  When this is true, the interpreter 
  159.  * does not print out things like "execution begins" or information
  160.  * about the number of byte codes executed.
  161.  */
  162. static Boolean        runQuietly = false;
  163.  
  164.  
  165. /* The complete list of "kernel" class and method definitions.  Each of
  166.  * these files is loaded, in the order given below.  Their last modification
  167.  * dates are compared against that of the image file; if any are newer,
  168.  * the image file is ignored, these files are loaded, and a new image file
  169.  * is created.
  170.  */
  171. static char        *standardFiles[] = {
  172.   "builtins.st", 
  173.   "Object.st",
  174.   "Message.st",
  175.   "Magnitude.st",
  176.   "Character.st",
  177.   "Date.st",
  178.   "Time.st",
  179.   "Number.st",
  180.   "Float.st",
  181.   "Integer.st",
  182.   "LookupKey.st",
  183.   "Association.st",
  184.   "Link.st",
  185.   "Process.st",
  186.   "Collection.st",
  187.   MAP_FILE("SequenceableCollection.st", "SeqColl.st"),
  188.   "LinkedList.st",
  189.   "Semaphore.st",
  190.   MAP_FILE("ArrayedCollection.st", "ArrColl.st"),
  191.   "Array.st",
  192.   "String.st",
  193.   "Symbol.st",
  194.   "ByteArray.st",
  195.   MAP_FILE("CompiledMethod.st", "CompileMth.st"),
  196.   "Interval.st",
  197.   MAP_FILE("OrderedCollection.st", "OrdColl.st"),
  198.   MAP_FILE("SortedCollection.st", "SortedColl.st"),
  199.   "Bag.st",
  200.   MAP_FILE("MappedCollection.st", "MappedColl.st"),
  201.   "Set.st",
  202.   "Dictionary.st",
  203.   MAP_FILE("IdentityDictionary.st", "IdentDict.st"),
  204.   MAP_FILE("SystemDictionary.st", "SysDict.st"),
  205.   "Stream.st",
  206.   MAP_FILE("PositionableStream.st", "PosStream.st"),
  207.   "ReadStream.st",
  208.   "WriteStream.st",
  209.   MAP_FILE("ReadWriteStream.st", "RWStream.st"),
  210.   "FileStream.st",
  211.   "TokenStream.st",
  212.   "Random.st",
  213.   MAP_FILE("UndefinedObject.st", "UndefObj.st"),
  214.   "Boolean.st",
  215.   "False.st",
  216.   "True.st",
  217. #if !defined(USG) && !defined(atarist)
  218.   "ProcessorScheduler.st",
  219. #else
  220.   "ProcSched.st",
  221. #endif
  222.   "Delay.st",
  223.   "SharedQueue.st",
  224.   "Behavior.st",
  225.   MAP_FILE("ClassDescription.st", "ClassDescr.st"),
  226.   "Class.st",
  227.   "Metaclass.st",
  228.   MAP_FILE("MethodContext.st", "MthContext.st"),
  229.   MAP_FILE("BlockContext.st", "BlkContext.st"),
  230.   "Memory.st",
  231.   "WordMemory.st",
  232.   "ByteMemory.st",
  233.   "MethodInfo.st",
  234.   "FileSegment.st",
  235.   "SymLink.st",
  236.   "initialize.st",
  237.   "CFuncs.st",
  238.   "Autoload.st",
  239.   nil
  240. };
  241.  
  242. #ifdef atarist
  243. long _stksize = -1L;        /* what does this do? */
  244. #endif
  245. main(argc, argv)
  246. int    argc;
  247. char     **argv;
  248. {
  249.   Boolean    loadBinary, traceUserDeclarations, traceUserExecution;
  250.   int        filesProcessed;
  251.   char        *imageName;
  252.  
  253. #ifdef USE_MONCONTROL
  254.   moncontrol(0);        /* don't monitor the initial stuff */
  255. #endif /* USE_MONCONTROL */
  256.  
  257.   yydebug = 0;
  258.   traceKernelDeclarations = declareTracing = false;
  259.   traceKernelExecution = executionTracing = false;
  260.   regressionTesting = false;
  261.   ignoreImage = false;
  262.   verbose = false;
  263.  
  264.   initSignals();
  265.   initMem();
  266.   initCFuncs();
  267.   initPaths();
  268. #if defined(USG)
  269.   tzset();
  270. #endif
  271.  
  272.   parseArgs(argc, argv);
  273.  
  274.   imageName = defaultImageName;
  275.  
  276.   if (binaryImageName) {
  277.     loadBinary = true;
  278.     imageName = binaryImageName;
  279.   } else if (ignoreImage) {
  280.     loadBinary = false;
  281.   } else {
  282.     loadBinary = okToLoadBinary(defaultImageName);
  283.   }
  284.  
  285.   if (loadBinary && loadFromFile(imageName)) {
  286.     initDefaultCompilationEnvironment();
  287.     initSTDIOObjects();
  288.     initInterpreter();
  289.     gcOn();
  290.   } else {
  291.     initOOPTable();
  292.     initDictionary();
  293.     initSymbols();
  294.     initInterpreter();
  295.  
  296.     installInitialMethods();
  297.  
  298.     traceUserDeclarations = declareTracing;
  299.     traceUserExecution = executionTracing;
  300.     if (!traceKernelDeclarations) {
  301.       declareTracing = false;
  302.     }
  303.     if (!traceKernelExecution) {
  304.       executionTracing = false;
  305.     }
  306.  
  307.     gcOn();
  308.     loadStandardFiles();
  309.  
  310.     declareTracing = traceUserDeclarations;
  311.     executionTracing = traceUserExecution;
  312.  
  313. /* ***    gcOn(); *** */
  314.     saveToFile(defaultImageName);
  315.   }
  316.  
  317. #ifdef preserved /* Sun Mar 26 23:36:15 1989 */
  318. /**/#ifdef profiling
  319. /**/  monitor(0);
  320. /**/
  321. /**/  printf("results %d/%d\n", hits, misses);
  322. /**/  { int i;
  323. /**/    for (i = 0; i < 10240; i++) {
  324. /**/      if (hitsOn[i]) {
  325. /**/    printf("hitsOn[%d] = %4d\t%d\t%4x\t%8o", i, hitsOn[i],
  326. /**/           i, i, i);
  327. /**/    printObject(oopAt(i));
  328. /**/    printf("\n");
  329. /**/      }
  330. /**/    }
  331. /**/  }
  332. /**/#endif /* profiling */
  333. #endif /* preserved Sun Mar 26 23:36:15 1989 */
  334.  
  335. #ifdef USE_MONCONTROL
  336.   moncontrol(1);
  337. #endif /* USE_MONCONTROL */
  338.  
  339.   invokeInitBlocks();
  340.   loadUserInitFile();
  341.  
  342. #ifdef symbol_table_profiling
  343.   printf("%d adds, %d reused %d reprobes\n", adds, reused, reprobes);
  344.  
  345.   { int i;
  346.     for (i = 0; i < OOP_TABLE_SIZE; i++) {
  347.       if (hitsOn[i]) {
  348.     printf("hitsOn[%d] = %4d\t%d\t%4x\t%8o", i, hitsOn[i],
  349.            i, i, i);
  350.     printObject(oopAt(i));
  351.     printf("\n");
  352.       }
  353.     }
  354.   }
  355. #endif /* symbol_table_profiling */
  356.  
  357.   if (regressionTesting) {
  358.     printf("Smalltalk Ready\n\n");
  359.   } else {
  360.     printf("Smalltalk %d.%d Ready\n\n", sysVersMajor, sysVersMinor);
  361.   }
  362.  
  363.   quietExecution = runQuietly | emacsProcess;
  364. #ifndef LEXDEBUG
  365.   for (filesProcessed = 0; *++argv; ) {
  366.     if (argv[0][0] != '-') {
  367.       processFile(argv[0], quietExecution);
  368.       filesProcessed++;
  369.     } else if (argv[0][1] == '-' || argv[0][1] == '\0') {
  370.       /* either - by itself or -- indicates standard input */
  371.       initLexer(false);
  372. #ifdef USE_READLINE
  373.       pushReadlineString();
  374. #else
  375.       pushUNIXFile(stdin, "stdin");
  376. #endif /* USE_READLINE */
  377.       yyparse();
  378.       popStream(true);
  379.     }
  380.   }
  381.  
  382.   if (filesProcessed == 0) {    /* didn't do any from cmd line, so read stdin*/
  383.     initLexer(false);
  384. #ifdef USE_READLINE
  385.     pushReadlineString();
  386. #else
  387.     pushUNIXFile(stdin, "stdin");
  388. #endif /* USE_READLINE */
  389.     yyparse();
  390.   }
  391.  
  392. #ifdef USE_MONCONTROL
  393.    moncontrol(0);
  394. #endif /* USE_MONCONTROL */
  395.  
  396. #else /* debugging the lexer */
  397.  
  398. #ifdef USE_READLINE
  399.     pushReadlineString();
  400. #else
  401.     pushUNIXFile(stdin, "stdin");
  402. #endif /* USE_READLINE */
  403.  
  404. /********* THIS IS NOT UP TO DATE ... BEWARE ************/
  405.  
  406.   lexDebug = 1;
  407.   while(!feof(infile)) {
  408.     switch (yylex()) {
  409.     case DOT:
  410.       printf("DOT\n");
  411.       break;
  412.     case BANG:
  413.       printf("BANG\n");
  414.       break;
  415.     case COLON:
  416.       printf("COLON\n");
  417.       break;
  418.     case VERTICAL_BAR:
  419.       printf("VERTICAL_BAR\n");
  420.       break;
  421.     case UPARROW:
  422.       printf("UPARROW\n");
  423.       break;
  424.     case ASSIGN:
  425.       printf("ASSIGN\n");
  426.       break;
  427.     case SHARP:
  428.       printf("SHARP\n");
  429.       break;
  430.     case SEMICOLON:
  431.       printf("SEMICOLON\n");
  432.       break;
  433.     case OPEN_PAREN:
  434.       printf("OPEN_PAREN\n");
  435.       break;
  436.     case CLOSE_PAREN:
  437.       printf("CLOSE_PAREN\n");
  438.       break;
  439.     case OPEN_BRACKET:
  440.       printf("OPEN_BRACKET\n");
  441.       break;
  442.     case CLOSE_BRACKET:
  443.       printf("CLOSE_BRACKET\n");
  444.       break;
  445.     case IDENTIFIER:
  446.       printf("IDENTIFIER: %s\n", yylval.sval);
  447.       break;
  448.     case INTEGER_LITERAL:
  449.       printf("INTEGER_LITERAL: %d\n", yylval.ival);
  450.       break;
  451.     case FLOATING_LITERAL:
  452.       printf("FLOATING_LITERAL: %g\n", yylval.fval);
  453.       break;
  454.     case CHAR_LITERAL:
  455.       printf("CHAR_LITERAL: %c\n", yylval.cval);
  456.       break;
  457.     case STRING_LITERAL:
  458.       printf("STRING_LITERAL: %s\n", yylval.sval);
  459.       break;
  460.     case BINOP:
  461.       printf("BINOP: %d\n", yylval.op);
  462.       break;
  463.     }
  464.   }
  465. #endif /* LEXDEBUG */
  466. }
  467.  
  468. /*
  469.  *    static void initPaths()
  470.  *
  471.  * Description
  472.  *
  473.  *    Sets up the paths for the kernel source directory and for where the
  474.  *    saved Smalltalk binary image lives.  Uses environment variables
  475.  *    SMALLTALK_KERNEL and SMALLTALK_IMAGE if they are set, otherwise uses
  476.  *    the paths assigned in mstpaths.h.
  477.  *
  478.  */
  479. static void initPaths()
  480. {
  481.   if ((kernelFileDefaultPath = (char *)getenv("SMALLTALK_KERNEL")) == nil) {
  482.     kernelFileDefaultPath = KERNEL_PATH;
  483.   }
  484.  
  485.   if ((imageFileDefaultPath = (char *)getenv("SMALLTALK_IMAGE")) == nil) {
  486.     imageFileDefaultPath = IMAGE_PATH;
  487.   }
  488. }
  489.  
  490. static Boolean okToLoadBinary(imageFileName)
  491. char    *imageFileName;
  492. {
  493.   unsigned long    imageFileTime;
  494.   char        **fileNames, fullFileName[MAXPATHLEN],
  495.           fullImageName[MAXPATHLEN];
  496.  
  497.   findImageFile(imageFileName, fullImageName);
  498.   imageFileTime = getFileModifyTime(fullImageName);
  499.  
  500.   if ((long)imageFileTime == -1) { /* not found */
  501.     return (false);
  502.   }
  503.  
  504.   for (fileNames = standardFiles; *fileNames; fileNames++) {
  505.     findKernelFile(*fileNames, fullFileName);
  506.     if (imageFileTime < getFileModifyTime(fullFileName)) {
  507.       return (false);
  508.     }
  509.   }
  510.  
  511.   return (true);
  512. }
  513.  
  514. static unsigned long getFileModifyTime(fileName)
  515. char    *fileName;
  516. {
  517.   struct stat    st;
  518.  
  519.   if (stat(fileName, &st) < 0) {
  520.     return ((unsigned long) -1);
  521.   } else {
  522.     return (st.st_mtime);
  523.   }
  524. }
  525.  
  526. /*
  527.  *    static void loadStandardFiles()
  528.  *
  529.  * Description
  530.  *
  531.  *    Loads the kernel Smalltalk files.  It uses a vector of file names, and
  532.  *    loads each file individually.  To provide for greater flexibility, if a
  533.  *    one of the files exists in the current directory, that is used in
  534.  *    preference to one in the default location.  The default location can be
  535.  *    overridden at runtime by setting the SMALLTALK_KERNEL environment
  536.  *    variable. 
  537.  *
  538.  */
  539. static void loadStandardFiles()
  540. {
  541.   char        **fileNames, fullFileName[MAXPATHLEN];
  542.   
  543.   for (fileNames = standardFiles; *fileNames; fileNames++) {
  544.     findKernelFile(*fileNames, fullFileName);
  545.     if (!processFile(fullFileName, true)) {
  546.       fprintf(stderr,
  547.           "Can't find system file '%s', proceeding without it.\n",
  548.           fullFileName);
  549.     }
  550.   }
  551. }
  552.  
  553.  
  554. /*
  555.  *    static void findKernelFile(fileName, fullFileName)
  556.  *
  557.  * Description
  558.  *
  559.  *    Attempts to find a viable kernel Smalltalk file (.st file).  First
  560.  *    tries the current directory to allow for overriding installed kernel
  561.  *    files.  If that isn't found, the full path name of the installed kernel
  562.  *    file is stored in fullFileName.  Note that the directory part of the
  563.  *    kernel file name in this second case can be overridden by defining the
  564.  *    SMALLTALK_KERNEL environment variable to be the directory that should
  565.  *    serve as the kernel directory instead of the installed one.
  566.  *
  567.  * Inputs
  568.  *
  569.  *    fileName: 
  570.  *        A simple file name, sans directory.
  571.  *    fullFileName: 
  572.  *        The file name to use for the particular kernel file is returned
  573.  *        in this variable (which must be a string large enough for any
  574.  *        file name).  If there is a file in the current directory with
  575.  *        name "fileName", that is returned; otherwise the kernel path is
  576.  *        prepended to fileName (separated by a slash, of course) and
  577.  *        that is stored in the string pointed to by "fullFileName".
  578.  *
  579.  */
  580. static void findKernelFile(fileName, fullFileName)
  581. char *fileName, *fullFileName;
  582. {
  583.   if (access(fileName, R_OK) == 0) {
  584.     strcpy(fullFileName, fileName);
  585.   } else {
  586.     sprintf(fullFileName, "%s/%s", kernelFileDefaultPath, fileName);
  587.   }
  588. }
  589.  
  590.  
  591. static void loadUserInitFile()
  592. {
  593.   char        fileName[MAXPATHLEN], *home;
  594.  
  595.   if ((home = (char *)getenv("HOME")) != nil) {
  596.     sprintf(fileName, "%s/%s", home, INIT_FILE_NAME);
  597.     processFile(fileName, quietExecution);
  598.   }
  599. }
  600.  
  601. static Boolean processFile(fileName, quiet)
  602. char    *fileName;
  603. Boolean    quiet;
  604. {
  605.   FILE        *file;
  606.  
  607.   file = fopen(fileName, "r");
  608.   if (file == NULL) {
  609.     return (false);
  610.   }
  611.  
  612.   if (verbose) {
  613.     printf("Processing %s\n", fileName);
  614.   }
  615.  
  616.   quietExecution = quiet;
  617.   initLexer(false);
  618.   pushUNIXFile(file, fileName);
  619.   yyparse();
  620.   popStream(true);
  621.  
  622.   return (true);
  623. }
  624.  
  625. /*
  626.  *    static void findImageFile(fileName, fullFileName)
  627.  *
  628.  * Description
  629.  *
  630.  *    Attempts to find a viable Smalltalk image file.  First
  631.  *    tries the current directory to allow for overriding installed image
  632.  *    files.  If that isn't found, the full path name of the installed image
  633.  *    file is stored in fullFileName.  Note that the directory part of the
  634.  *    image file name in this second case can be overridden by defining the
  635.  *    SMALLTALK_IMAGE environment variable to be the directory that should
  636.  *    serve as the image directory instead of the installed one.
  637.  *
  638.  * Inputs
  639.  *
  640.  *    fileName: 
  641.  *        A simple file name, sans directory.
  642.  *    fullFileName: 
  643.  *        The file name to use for the particular image file is returned
  644.  *        in this variable (which must be a string large enough for any
  645.  *        file name).  If there is a file in the current directory with
  646.  *        name "fileName", that is returned; otherwise the kernel path is
  647.  *        prepended to fileName (separated by a slash, of course) and
  648.  *        that is stored in the string pointed to by "fullFileName".
  649.  *
  650.  */
  651. void findImageFile(fileName, fullFileName)
  652. char *fileName, *fullFileName;
  653. {
  654.   if (access(fileName, R_OK) == 0) {
  655.     strcpy(fullFileName, fileName);
  656.   } else {
  657.     sprintf(fullFileName, "%s/%s", imageFileDefaultPath, fileName);
  658.   }
  659. }
  660.  
  661.  
  662. /*
  663.  *    static void parseArgs(argc, argv)
  664.  *
  665.  * Description
  666.  *
  667.  *    This routine scans the command line arguments, accumulating information
  668.  *    and setting flags.  This will probably be replaced by getopt in a
  669.  *    future version of Smalltalk.
  670.  *
  671.  * Inputs
  672.  *
  673.  *    argc  : The number of arguments present
  674.  *    argv  : Vector of strings that are the arguments.
  675.  *
  676.  */
  677. static void parseArgs(argc, argv)
  678. int    argc;
  679. char    **argv;
  680. {
  681.   char        **hp, **av;
  682.   char        *flags;
  683.  
  684.   static char    *helpText[] = {
  685. "GNU Smalltalk usage:",
  686. "",
  687. "    mst [ flag ... ] [ file ...]",
  688. "",
  689. "Flags can appear either as -xyz or as -x -y -z.  The currently",
  690. "defined set of flags is:",
  691. "  -c\tDump core on fatal signal",
  692. "  -d\tTrace compilation of user specified files",
  693. "  -D\tTrace compilation of kernel and user files",
  694. "  -e\tTrace execution of files specified on command line",
  695. "  -E\tTrace execution of kernel and user files",
  696. "  -H -h -?  Print this message and exit",
  697. "  -i\tIgnore the image file; rebuild it from scratch",
  698. "  -I file\tUse 'file' as the image file, instead of 'mst.im'",
  699. "  -p\tRun Smalltalk as a 'process', i.e. from within GNU Emacs",
  700. "  -q\tRun Smalltalk without printing execution information",
  701. "  -r\tRun in regression test mode (printed messages are made constant)",
  702. "  -v\tPrint the Smalltalk version number",
  703. "  -V\tEnable verbose mode",
  704. "  -y\tTurn on debugging in the parser",
  705. "  - --\tRead input from standard input explicitly",
  706. "",
  707. "Files are loaded one after the other.  After the last one is loaded,",
  708. "Smalltalk will exit.  If no files are specified, Smalltalk reads from",
  709. "the terminal, with prompts.",
  710. NULL
  711. };
  712.  
  713.  
  714.   for ( ; *++argv; ) {
  715.     if (argv[0][0] == '-') {
  716.       for (flags = &argv[0][1]; *flags; flags++) {
  717.     switch (*flags) {
  718.     case 'c':
  719.       makeCoreFile = true;
  720.       break;
  721.     case 'D':
  722.       traceKernelDeclarations = true; /* fall thru */
  723.     case 'd':
  724.       declareTracing = true;
  725.       break;
  726.     case 'E':
  727.       traceKernelExecution = true; /* fall thru */
  728.     case 'e':
  729.       executionTracing = true;
  730.       break;
  731.     case 'h': case 'H': case '?':
  732.     default:
  733.       for (hp = helpText; *hp != NULL; hp++) {
  734.         printf("%s\n", *hp);
  735.       }
  736.           exit(0);
  737.     case 'I':
  738.       binaryImageName = argv[1];
  739.       for (av = argv+1; *av; ) {    /* remove this argument */
  740.         *av = *++av;
  741.       }
  742.       break;
  743.     case 'i':
  744.       ignoreImage = true;
  745.       break;
  746.     case 'p':
  747.       emacsProcess = true;
  748.       break;
  749.     case 'q':
  750.       runQuietly = true;
  751.       break;
  752.     case 'r':
  753.       regressionTesting = true;
  754.       break;
  755.     case 'V':
  756.       verbose = true;
  757.       break;
  758.     case 'v':
  759.       printf("GNU Smalltalk version %d.%d\n", sysVersMajor, sysVersMinor);
  760.       printf("Copyright (C) 1988, 1989, 1990 Free Software Foundation, Inc.\n");
  761.       printf("Written by Steve Byrne.\n");
  762.       printf("Using kernel path: %s\n", kernelFileDefaultPath);
  763.       printf("Using image path : %s\n", imageFileDefaultPath);
  764.       break;
  765.     case 'y':
  766.       yydebug = 1;
  767.       break;
  768.     case '-':        /* this means standard input, so it's ok */
  769.       break;
  770.     }
  771.       }
  772.     }
  773.   }
  774.  
  775.   if (regressionTesting) {
  776.     traceKernelDeclarations = declareTracing = false;
  777.     traceKernelExecution = executionTracing = false;
  778.     verbose = false;
  779.   }
  780. }
  781.  
  782.